﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Tradex.Trading;

namespace Tradex.Messages {
    
    /// <summary>
    /// The OrderUpdate message is generated from a trading connection (real or simulated) and forwarded to the
    /// TradingService and from there to whatever is tracking order modifications.
    /// An OrderUpdate contains all relevant information about the status changes of an order, including executions.
    /// It does not track positions - this is done in the AccountUpdate part.
    /// </summary>
    [Serializable()]
    public class OrderUpdateMessage : Message {

        /// <summary>
        /// Constructor taking all properties.
        /// </summary>
        /// <param name="orderKey"></param>
        /// <param name="orderConnectionKey"></param>
        /// <param name="progress"></param>
        /// <param name="execution"></param>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
        public OrderUpdateMessage (
            OrderKey orderKey,
            OrderId orderConnectionKey,
            OrderUpdate progress = null,
            OrderExecution execution = null
        ) {
            OrderKey = orderKey;
            ConnectionKey = orderConnectionKey;
            Progress = progress;
            Execution = execution;
        }

        /// <inheritdoc />
        public override MessageCode Code { get { return MessageCode.OrderUpdate; } }

        /// <summary>
        /// This is the Tradex order key for the order to be updated. From the Connector, it must not be set
        /// (in which case the TradingService is going to assign one and track it based on the OrderConnectionKey).
        /// </summary>
        public OrderKey OrderKey { get; private set; }

        /// <summary>
        /// This is the native connection identifier on whatever system is tracking the order.
        /// </summary>
        public OrderId ConnectionKey { get; private set; }

        /// <summary>
        /// Gets the Progress of the order.
        /// </summary>
        public OrderUpdate Progress { get; private set; }

        /// <summary>
        /// Gets the reported execution, if one is reported.
        /// </summary>
        public OrderExecution Execution { get; private set; }

    }
}
